package com.leo.base_project.Utils;

import android.content.Context;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @program: BaseProject
 * @description: 文件管理类
 * @author: Leo
 * @create: 2021-03-29 15:44
 **/
public class FileUtils {

    public void output(String fileName, String file, Context context) {

        String path = context.getExternalFilesDir(null).getPath() + "files/" + fileName;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(path);
            fos.write(file.getBytes());
        } catch (Exception e) {
            UIUtils.toast("写出失败" + e.getMessage());
            e.printStackTrace();
        } finally {
            try {
                if (fos != null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                UIUtils.toast("写出流关闭失败" + e.getMessage());
            }
        }
        UIUtils.toast("写出成功于" + path);
    }


}
